<?php
namespace Admin\Controller;
use Think\Controller;
use Common\Controller\BaseController;

class StationController extends BaseController{
    public function add(){
        $this->assign('title','添加公司工作岗位');
        $this->assign('info','添加');
        $this->assign('url',U('Admin/Station/insert'));
        $this->display('Station_info');
    }
    public function insert(){
        $where['station']=I('post.station');
        $checkstation=D('Station')->where($where)->find();
        if ($checkstation>0){
            $this->error('工作岗位已经存在！');
        }else {
        if (D('Station')->getstation()){
            $this->success('添加成功！',U('Admin/Station/View'));
        }else {
            $this->error('添加失败！');
        }
        }     
    }
    public function edit(){
        $this->assign('title','工作岗位更新页面');
        $this->assign('info','更新');
        $this->assign('url',U('Admin/Station/update'));
        $this->assign('editstation',D('Station')->getid());
        $this->display('Station_info');
    }
    public function update(){
        $updates=D('Station');
        $result= $updates->updatestation();
      if (false !== $result || 0 !== $result){
          $this->success('更新成功！',U('Admin/Station/View'));
      }else {
          $this->error('更新失败！');
      }
    }
    
    public function delete(){
        if (D('Station')->delid()){
            $data['state']=1;
            $data['msg']='删除成功';
            $this->ajaxReturn($data);
        }else {
            $data['state']=0;
            $data['msg']='该岗位有员工存在，请先删除该岗位下的员工';
            $this->ajaxReturn($data);
        }
    }
    public function View(){
        $this->assign('title','岗位列表页'); 
        $this->assign('info','添加岗位');
        $this->assign('Stationlist',D('Station')->select());
        $this->display('Station_list');
    }
}